
<template>
	<div class="index">

		<div class="center">
			<left></left>
			<div class="right">
          <top></top>
          <!-- <div class="hei10"></div>
          <div class="where" style="background: #fff; padding: 10px 30px; font-size: 14px; color: #595959;">当前位置：分销后台><router-link to="/finance/tkzhichu">财务打款</router-link></div>
          --><div class="hei10"></div>
                <div class="powertop">
                <router-link class="powertopli " to="/finance/zhichu">佣金支出</router-link>
                <router-link class="powertopli powertopact" to="/finance/zhichu/tkzhichu">提卡费支出</router-link>
            </div>
                <div class="conlist" v-loading='loading'>

                    <div class="flex">
                        <div class="gong moneyf" style="margin: 0 20px 20px; font-size: 16px;">
                            待支付的提卡费
                        </div>
                        <div class="gong moneyf" style="margin: 0 20px 20px; font-size: 16px;">
                            <el-select v-model="status" placeholder="请选择">
                                <el-option label="未支付" value="0"></el-option>
                                <el-option label="已支付" value="100"></el-option>
                                <el-option label="全部" value="2"></el-option>
                            </el-select>
                            <el-button type="danger" @click="search">搜索</el-button>
                        </div>
                    </div>
                    <div class="list">

                        <div class="th">序号</div>
                        <div class="th">收款供货商</div>
                        <div class="th">待支付的提卡费金额</div>
                        <div class="th">提卡费订单数</div>
                        <div class="th">结算时间</div>
                        <div class="th">支付状态</div>
                        <div class="th">操作</div>
                    </div>
                    <div class="list" v-for="item in list" :key="item.id">

                        <div class="td">{{item.id}}</div>
                        <div class="td">{{item.parent_name}}</div>
                        <div class="td">{{item.sum_cost}}</div>
                        <div class="td">{{item.order_count}}</div>
                        <div class="td">{{item.created_at}}</div>
                        <div class="td" v-if="item.status == 100">已支付</div>
                        <div class="td" v-if="item.status != 100">未支付</div>
                        <div class="td" @click="chooseids(item.id)">
                            <el-button type="text" v-if="item.status == 100" @click="dakuan(item.payment_info)">查看明细</el-button>
                            <el-upload style=""  v-if="item.status != 100"  class="upload-demo" list-type="picture" :show-file-list='false' action="https://jsonplaceholder.typicode.com/posts/" :http-request="upup3">
                              <el-button type="text" >录入打款信息</el-button>
                            </el-upload>
                        </div>
                    </div>
                    <el-pagination background layout="total,prev, pager, next" :current-page="page" @current-change="fanye" :page-size="pagesize" :total="total"></el-pagination>
                </div>
            </div>
        </div>

        <el-dialog :title="choose.mobile" :visible.sync="tongjilog" width="400px" :close-on-click-modal='false'>
            <div class="daowei">所属商品编码:<span class="daowei2">{{choose.good_sku}}</span></div>
            <div class="daowei">返利次数:<span class="daowei2">{{choose.cycle}}</span></div>
            <div class="daowei">已领取次数:<span class="daowei2">{{choose.rebate_cycle}}</span></div>
            <div class="daowei">已领取积分:<span class="daowei2">{{choose.points}}</span></div>
            <div class="daowei">已充值话费:<span class="daowei2">{{choose.recharged_amount}}</span></div>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="tongjilog = false">确 定</el-button>
            </span>
        </el-dialog>


        <el-dialog title="导入结果" :visible.sync="shoplog" :close-on-click-modal="false" width="600px">
              <div>
                  <div style="color: #077ECE; line-height: 30px;">成功{{shoplist.success}}条</div>
                  <div style="color: #DF3434; line-height: 30px;">失败及原因：
                      <div v-for="(item,i) in shoplist.erros" :key="i">
                          {{item}}
                      </div>
                  </div>
              </div>
              <div slot="footer" class="dialog-footer">
                  <el-button type="primary" size="small"  @click="shoplog = false">好的</el-button>
              </div>
        </el-dialog>
        <el-dialog title="修改返利领取时间" :visible.sync="monthfixlog" :close-on-click-modal="false" width="600px">
            <el-form ref="form" @submit.native.prevent label-width="80px">
                <el-form-item label="起始月份:">
                    <el-date-picker v-model="monthfix" type="month" value-format="yyyy-MM" placeholder="选择起始月份"> </el-date-picker>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                  <el-button type="primary" size="small"  @click="fixtimego">好的</el-button>
              </div>
        </el-dialog>
        <el-dialog title="查看打款详情" :visible.sync="dakuanlog" :close-on-click-modal="false" width="600px">
            <div>
              <img :src="imageurl"  style="width: 100%;"/>
            </div>
            <div slot="footer" class="dialog-footer">
                  <el-button type="primary" size="small"  @click="dakuanlog = false">好的</el-button>
              </div>
        </el-dialog>
        <el-dialog title="银行卡信息" :visible.sync="yinhang" :close-on-click-modal="false" width="600px">
            <div>
              <div class="yinhangrow">
                <div>银行：</div><div>{{yinhangkaxinxi.bank}}</div>
              </div>
              <div class="yinhangrow"><div>开户人：</div><div>{{yinhangkaxinxi.bank_person}}<el-button type="text" size="mini" @click="copy(yinhangkaxinxi.bank_person)">复制</el-button></div></div>
              <div class="yinhangrow"><div>银行卡账号：</div><div>{{yinhangkaxinxi.bank_account}}<el-button type="text" size="mini" @click="copy(yinhangkaxinxi.bank_account)">复制</el-button></div></div>
              <div class="yinhangrow"><div>银行卡开户地址：</div><div>{{yinhangkaxinxi.open_bank}}</div></div>
			  <div class="yinhangrow"><div>开户人身份证号：</div><div>{{yinhangkaxinxi.user_id_num}}</div></div>
            </div>
        </el-dialog>
        <!-- <foot></foot> -->
    </div>

</template>

<script>
    import axios from 'axios'
    import top from '@/components/top.vue'
    import left from '@/components/left.vue'
    import foot from '@/components/foot.vue'
    import moment from "moment";
    import UploadExcelComponent from "@/components/UploadExcel/index.vue";
    export default {
        components: {
            "left": left,
            "top": top,
            "foot": foot,
            UploadExcelComponent

        },
        name: "tkzhichu",
        data() {
            return {
                shenqingren:"",
                qrstatus:"2,3",
                qrmonth:"",
                form:{},
                monthfixlog:false,
                monthfix:"",
                monthfixall:{},
                wenjian:"",
                shoplog:false,
                shoplist:"",

                btnname:"点击导入",
                uploading:true,
                fanliuploadlog:false,
                uploadsuceess:"",
                uploadtimes:"",
                uploadmon1:"",
                uploadmon2:"",
                uploadmon3:"",
                uptime:"",
                month:"",
                monthsearch:"",
                total:0,
                pagesize:20,
                page:1,
                list:"",
                loading:true,
                mobile:"",
                sku:"",
                tongjilog:false,
                choose:{ },
                url:"",
                id:"",
                func_J02:false,
                leader:0,
                dakuanlog:false,
                start:"",
                end:"",
                chooseid:"",
                imageurl:"",
                yinhang:false,
                yinhangkaxinxi:"",
                status:""
            }
        },
        created() {
            this.url = window.location.origin+"/"

            //权限问题
            var user = JSON.parse(localStorage.getItem('USER'));
            this.user_func = user.functions
            for( var i in this.user_func){
                var func_number = this.user_func[i].code
                if(func_number.indexOf("J02") >= 0){ this.func_J02 = true }
                if(func_number.indexOf("J01") >= 0){ this.func_J01 = true }
                if(func_number.indexOf("J03") >= 0){ this.leader = 1 }
            }

            var shop = JSON.parse(localStorage.getItem('SHOP'));
            this.shopname = shop.shop_name
            var that = this

            // this.monthsearch = moment().format("YYYY-MM");
            // this.uploadmon1 = moment().subtract(1, 'months').format("YYYY-MM");
            // this.uptime = moment().format("YYYY-MM");
            // this.uploadmon2 = moment().format("YYYY-MM");
            // this.uploadmon3 = moment().add(1, 'months').format("YYYY-MM");

            // console.log(moment().format("YYYY-MM"))

            this.getlist()

        },
        mounted() {

        },
        methods: {
          //复制功能
          copy: function(t) {
            var that = this;
            this.$copyText(t).then(res => {
              that.$message.success("复制成功");
            });
          },
            getbindcard:function(id){
              var that = this
              axios.get('/api/plan-market/commission/getbindcarddan?id='+id)
                .then(response => {
                  if(response.data.msg.code == 0){
                      that.yinhangkaxinxi = response.data.data
                      if(response.data.data.bank != ''){
                          that.yinhang = true
                      }else{
                        that.$message.error("对方没有填写银行信息");
                      }
                  }else{
                      that.$message.error(response.data.msg.info);
                  }
                })
            },
            dakuan:function(url){
                this.imageurl = this.url + url
                this.dakuanlog = true
            },
            timechange:function(){
                console.log(this.monthsearch)
                this.start = this.monthsearch[0]
                this.end = this.monthsearch[1]
            },
            //上传凭证
            upup3:function(file){
              this.wenjian = file.file
              var that = this
              var params = new FormData();
              params.append('file',this.wenjian);
              params.append('id',this.chooseid);
              axios.post("/api/plan-market/tika/pay", params)
                  .then(function(response) {
                      if (response.data.msg.code == 0) {
                          that.$message.success("上传成功！");
                          that.loading = true
                          that.getlist()
                      }else{
                          that.$message.error(response.data.msg.info);
                      }
                  })
            },
            deletes:function(id){
               var iid = id
               this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                      confirmButtonText: '确定',
                      cancelButtonText: '取消',
                      type: 'warning'
                    }).then(() => {

                      var that = this
                      axios.post('/api/plan-market/income/delete',{id:iid})
                          .then(response => {
                              if(response.data.msg.code == 0){
                                  that.getlist()
                              }else{
                                  that.$message.error(response.data.msg.info);
                              }
                          })
                    })

            },
            chooseids:function(e){

              this.chooseid = e
              console.log(this.chooseid)
            },
            // exportData(data) {
            //     console.log(data)
            //     var that = this;
            //     var list = [];
            //     for (var i = 0; i < data.results.length; i++) {
            //       var obj = {};
            //       obj["confirm"] = data.results[i]["是否确认"];
            //       obj["id"] = data.results[i]["id"];
            //       obj["commission_amount"] = data.results[i]["本次应发"];
            //       obj["amount"] = data.results[i]["本次实发"];
            //       list.push(obj);
            //     }
            //     axios.post('/api/plan-market/confirm/import',{data:list,id:this.id})
            //     	.then(response => {
            //     		if(response.data.msg.code == 0){
            //           that.shoplist = response.data.data
            //           that.shoplog = true
            //           that.loading = false
            //     		}else{
            //     			that.$message.error(response.data.msg.info);
            //     		}
            //     	})
            // },
            //统计
            tongji:function(id){
                var that = this
                axios.get('/api/plan-market/rebate/log/detail?log_id='+id)
                	.then(response => {
                		if(response.data.msg.code == 0){
                            that.choose = response.data.data
                		}else{
                			that.$message.error(response.data.msg.info);
                		}
                	})
                this.tongjilog = true
            },
            //修改时间
            fixtime:function(id,mobile,month){
                this.monthfixall.id = id
                this.monthfixall.mobile = mobile
                this.monthfixall.month = month
                this.monthfixlog = true
            },
            fixtimego:function(){

                var qtime = this.monthfixall.month.toString()
                qtime = qtime.substr(0,4) + '-' + qtime.substr(5,2)

                var that = this
                axios.post("/api/plan-market/rebate/log/cycle", {order_id:this.monthfixall.id,mobile:this.monthfixall.mobile,month_ago:qtime,month_now:this.monthfix})
                    .then(function(response) {
                        if (response.data.msg.code == 0) {
                            that.monthfixlog = false
                            that.getlist()
                        }else{
                            that.$message.error(response.data.msg.info);
                        }
                    })
            },
            //暂停领取
            stopget:function(id){
                this.loading = true
                var that = this
                axios.post("/api/plan-market/rebate/log/status", { log_id:id,status:-100})
                    .then(function(response) {
                        if (response.data.msg.code == 0) {
                            that.getlist()
                        }else{
                            that.$message.error(response.data.msg.info);
                        }
                    })
            },
            //开放领取
            startget:function(id){
                this.loading = true
                var that = this
                axios.post("/api/plan-market/rebate/log/status", { log_id:id,status:100})
                    .then(function(response) {
                        if (response.data.msg.code == 0) {
                            that.getlist()
                        }else{
                            that.$message.error(response.data.msg.info);
                        }
                    })
            },
            //导出
            daochu:function(){
                axios.get('/api/plan-market/rebate/export?&month='+this.monthsearch)
                	.then(response => {
                		if(response.data.msg.code == 0){
                            location.href = response.data.data
                		}else{
                			that.$message.error(response.data.msg.info);
                		}
                	})
            },
            search:function(){
                this.getlist()
            },
            //翻页
            fanye:function(page){
            	this.loading = true
            	this.page = page
            	this.getlist()
            },
            //获取列表
            getlist:function(){
                var that = this
                if(this.status == 2){
                  this.status = ''
                }
                axios.get('/api/plan-market/tika/parent/slist?status='+this.status)
                	.then(response => {
                		if(response.data.msg.code == 0){
                      that.list = response.data.data.data
                      that.total = response.data.data.total
                      that.loading = false
                		}else{
                			that.$message.error(response.data.msg.info);
                		}
                	})
            },
            //下面使用的格式化时间
            formatDate:function(numb) {
              const time = new Date((numb - 1) * 24 * 3600000 + 1)
              time.setYear(time.getFullYear() - 70)
              const year = time.getFullYear() + ''
              const month = time.getMonth() + ''
              let date = time.getDate() + ''
              if(time.getFullYear()%4 === 0){
                var X = moment([year, month, date]).subtract(1, 'days').format('YYYY-MM-DD');
              }else{
                var X = moment([year, month, date]).format('YYYY-MM-DD');
              }
              return X
            },
            //下载模板
            xiazai:function(){
                const a = document.createElement('a');
                a.setAttribute('download', '收入导入模板.xlsx');
                a.setAttribute('href', this.url+'91haoka_platform/static/Incomeupload.xlsx');
                a.click();
            },
            xiabiao:function(e){
                const a = document.createElement('a');
                a.setAttribute('href', this.url+e);
                a.click();
            },
            xiabiao2:function(e){
                const a = document.createElement('a');
                a.setAttribute('href', this.url+e);
                a.click();
            },
            upup:function(file){
              console.log(file.file)
              this.wenjian = file.file
              var that = this
              this.loading = true
              var params = new FormData();
              params.append('file',this.wenjian);
              axios.post("/api/plan-market/income/import", params)
                      .then(function(response) {
                          if (response.data.msg.code == 0) {
                              that.shoplist = response.data.data
                              that.shoplog = true
                              that.loading = false
                              that.getlist()
                          }else{
                              that.$message.error(response.data.msg.info);
                          }
                      })
            },
            upup2:function(file){
              this.wenjian = file.file
              var that = this
              this.loading = true
              var params = new FormData();
              params.append('file',this.wenjian);
              params.append('file_id',this.id);
              axios.post("/api/plan-market/confirm/import", params)
                  .then(function(response) {
                      if (response.data.msg.code == 0) {
                          that.$message.success("导入确认表成功！");
                          that.getlist()
                      }else{
                          that.$message.error(response.data.msg.info);
                      }
                  })
            }
        }
    }
</script>

<style lang="scss" scoped>
    .index{
        .listupload{ font-size: 14px;
            .li{flex: 1; line-height: 38px; margin-top: 20px;}
        }
        .yinhangrow{ display: flex; line-height: 28px; margin-bottom: 10px;
          div:nth-child(1){ color:#999; flex: 1; text-align: right;}
          div:nth-child(2){ color:#666; flex: 1; margin-right: 10px;
            span{ margin-left: 15px;}
          }
        }
        .moneyf{
          .el-button--primary{ background: #409EFF; color: #ffffff; border: none; }
          .el-button{ height: 36px !important;}
          .el-date-editor.el-input, .el-date-editor.el-input__inner{ width: auto;}
        }
        .form{ display: flex;
          input{ width: 150px !important;}
        }
        .listth{ font-size: 14px;  border-bottom: 1px #EAEAEA solid; font-weight: bold;}
        .daowei{ margin-bottom: 20px;}
        .daowei2{ color: #DD2727; margin-left: 10px;}
        .moneylist{ display: flex;}
        .erimg{ width: 200px;}
        .red{ border: 1px #FF3B3B solid !important; color: #FF3B3B !important;}
        .moneylist div{ border: 1px #AAAAAA solid; width: 85px; height: 35px; line-height: 35px; text-align: center; margin-right: 10px; cursor: pointer;}

                .title{border-bottom: 1px #EAEAEA solid;  line-height: 45px; padding-left: 30px; font-size: 16px; background: #F9F9F9; color: #727272}


            .powertop{ display: flex; background:#f9f9f9; }
            .powertopli{ flex-basis: 160px; line-height: 45px; border-top: 4px #F9F9F9 solid; color: #727272; border-right: 1px #F9F9F9 solid; font-size: 14px; text-align: center;}
            .powertopact{ background: #FFFFFF; border-top: 4px #DD2727 solid;}
            .con{  background: #FFFFFF; padding: 30px 40px; display: flex; justify-content: space-between;
                .conleft{
                    .flex{ display: flex; margin-bottom: 20px;}
                    .gong{ margin-right: 30px; color: #333}
                }
                .conright{
                    .el-input__inner{ line-height: 40px !important; height: 40px !important;}
                }
            }
            .conlist{ padding-bottom: 20px; background: #FFFFFF; min-height: 800px;
                .flex{ display: flex; justify-content: space-between; padding-top: 30px;}
                .tkli{ background: url(../../../static/img/changhui.png) no-repeat; line-height: 38px; color:#666; text-align: center; flex:1;}
                .gong{ display: flex;

                    .el-button--danger{ margin-left: 20px;}
                    .el-button--primary{ padding: 10px 30px; background: #EEF7FF; border: 1px #EEF7FF solid; }
                    .el-date-editor--month{ margin-right: 20px;}
                    button{  padding: 10px 20px;}
                }
                .gl{ margin-bottom: 20px;
                    .el-input__inner{ width: 200px !important; }
                    .el-button--danger{ margin-left: 0px !important; margin-right: 20px;}
                    .el-input__icon{ line-height: 36px;}
                }
                .list{ display: flex; border-bottom: 1px #eaeaea solid;
                    .th{ background: #EAEAEA; text-align: center; flex: 1; padding: 15px 0; font-size: 14px; }
                    .td{ background: #ffffff; text-align: center; flex: 1; padding: 5px 5px; height: 40px; font-size: 14px; line-height: 40px; overflow:
                    hidden;white-space: nowrap;text-overflow: ellipsis;}
                    .td2{ flex: 2; display: flex; justify-content: center; flex-wrap: wrap;}
                }
                .el-pagination{ text-align: right; margin: 20px 0}
            }

    }
</style>
